package com.woniuxy02;

import java.lang.reflect.Field;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 作者
 * @create 2025-09-23 17:14
 * 封装JDBC的操作
 */
public class JdbcUtil {
    //创建连接对象
    public static Connection getConnection() throws SQLException, ClassNotFoundException {
        String className="com.mysql.cj.jdbc.Driver";
        String url="jdbc:mysql://localhost:3306/db3";
        String user="root";
        String password="123";
        Class.forName(className);
        return DriverManager.getConnection(url, user, password);
    }

    public static void close(Connection conn, Statement stmt, ResultSet rs) throws SQLException {
        if(rs != null) {
            rs.close();
        }
        if(stmt != null) {
            stmt.close();
        }
        if(conn != null) {
            conn.close();
        }
    }

}
